﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Remoting.Messaging;

namespace ServiceController
{
    public delegate DataAccess.DataAccessResult UpgradeDeploymentDelegate(String SubscriptionID, String CertificatePath, String ServiceName, String DeploymentSlot, String mode, String PkgURL, String ConfigFile, String Label, String RoletoUpgrade);
    public partial class ServiceController
    {
        
        UpgradeDeploymentDelegate _UpgradeDeploymentDelegate;
        public void UpgradeDeploymentAsync(String SubscriptionID, String CertificatePath, String ServiceName, String DeploymentSlot, String mode, String PkgURL, String ConfigFile, String Label, String RoletoUpgrade, object UserState)
        {
            _UpgradeDeploymentDelegate.BeginInvoke(SubscriptionID, CertificatePath, ServiceName, DeploymentSlot, mode, PkgURL, ConfigFile, Label, RoletoUpgrade,
                new AsyncCallback(UpgradeDeploymentCallback), UserState);
        }

        private void UpgradeDeploymentCallback(IAsyncResult ar)
        {
            AsyncResult aresult = (AsyncResult)ar;
            DataAccess.DataAccessResult result = _UpgradeDeploymentDelegate.EndInvoke(ar);
            OnUpgradeDeploymentComplete(new ServiceControllerEventArgs()
            {
                error = result.Error,
                UserState = ar.AsyncState,
                IsOperationSuccessful = result.IsOperationSuccessful,
            });
        }

        private DataAccess.DataAccessResult UpgradeDeployment(String SubscriptionID, String CertificatePath, String ServiceName, String DeploymentSlot, String mode, String PkgURL, String ConfigFile, String Label, String RoletoUpgrade)
        {
            DataAccess.DataAccessResult result = da.UpgradeDeployment(SubscriptionID, CertificatePath, ServiceName, DeploymentSlot, mode, PkgURL, ConfigFile, Label, RoletoUpgrade);
            return result;
        }
    }
}
